﻿@using Mapster;
@using OnWork.DataCenter.BLL.Standard;
@using OnWork.DataCenter.BLL.DataCenter;
<ValidateForm Model="@config"
              OnValidSubmit="@OnValidSubmit">
    <Row ItemsPerRow="ItemsPerRow.One" RowType="RowType.Inline">
        <BootstrapInput DisplayText="可执行文件名称" @bind-Value="@config.FileName" />
        <BootstrapInput DisplayText="工作目录" @bind-Value="@config.WorkingDirectory" />
        <BootstrapInput DisplayText="命令行参数" @bind-Value="@config.Arguments" />
        <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Inline">
            <Switch DisplayText="是否显示窗体" @bind-Value="@config.IsShowWindowsForm"></Switch>
            <Switch DisplayText="管理员身份运行" @bind-Value="@config.IsRunAsAdmin"></Switch>
        </Row>
    </Row>
   

    <div class="form-footer mt-3">
        <DialogCloseButton />
        <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa-solid fa-floppy-disk" Text="保存" />
    </div>
</ValidateForm>


@code {
    /// <summary>
    /// Json转DataTable配置
    /// </summary>
    private OnWork.DataCenter.BLL.Standard.ExeToExeConfig config = new BLL.Standard.ExeToExeConfig() { };

    [Parameter]
    public Action? OnClose { get; set; }

    [Parameter]
    public Action<ExeToExeConfig>? OnSave { get; set; }


    [CascadingParameter(Name = "BodyContext")]
    private object? Context { get; set; }

    [CascadingParameter]
    private Modal? Dialog { get; set; }


    /// <summary>
    /// 注入BLL MQTT类型
    /// </summary>
    [Inject]
    private DSMqttBLL dsmqttBLL { get; set; }

    protected override void OnParametersSet()
    {
        base.OnParametersSet();

        if (Context is OnWork.DataCenter.BLL.Standard.ExeToExeConfig)
        {
            config = Context as OnWork.DataCenter.BLL.Standard.ExeToExeConfig;
        }
    }


    // /// <summary>
    // /// Mqtt 列表项目
    // /// </summary>
    // private IEnumerable<SelectedItem> MqttItems { get; set; }


    // protected override async Task OnAfterRenderAsync(bool firstRender)
    // {
    //     await base.OnAfterRenderAsync(firstRender);
    //     if (firstRender)
    //     {
    //         var result = await dsmqttBLL.QueryALLMqttAsync();
    //         if (result != null)
    //         {
    //             MqttItems = result.Select(x => new SelectedItem { Value = x.ID.ToString(), Text = x.Name }).ToList();
    //             StateHasChanged();
    //         }
    //     }

    // }

    private async Task OnValidSubmit(EditContext item)
    {
        // do someting like save model into db

        OnSave(config);

        // 关闭弹窗
        // close Dialog
        await Dialog.Close();

        // 显示 Toast 提示弹窗
        //await Toast.Show(new ToastOption() { Title = "保存数据", Content = "保存成功，4 秒后自动关闭" });
    }
}
